#ifndef MODEL_H
#define MODEL_H

#include "geometry.h"
#include "mathengine.h"
#include "tgaimage.h"
#include <memory>
#include <vector>

namespace raster {

typedef std::vector<std::shared_ptr<Triangle>> TriangleList;

using Vec3f = mathengine::Vec3f;
using Vec3i = mathengine::Vec3i;
using Vec2i = mathengine::Vec2i;
using Vec2f = mathengine::Vec2f;


class Model {
public:
    Model(const char *filename);
    ~Model() = default;

    int nverst();
    int nfaces();
    Vec3f norm(int iface, int nvert);
    Vec3f norm(Vec2f uvf);
    Vec3f vert(int i);
    Vec3f vert(int iface, int nvert);
    Vec2f uv(int iface, int nvert);
    TGAColor diffuse(Vec2f uvf);
    TGAColor specular(Vec2f uvf);
    std::vector<int> face(int idx);

    static TriangleList LoadObjs();
    static TriangleList generateSimpleTriangles();

private:
    std::vector<Vec3f> verts_;
    std::vector<std::vector<Vec3i>> faces_; // v/uv/normal, index
    std::vector<Vec3f> norms_;
    std::vector<Vec2f> uv_;
    TGAImage diffusemap_;  // Diffuse map
    TGAImage normalmap_;   // Normal map
    TGAImage specularmap_; // Specular map
    void loadTexture(std::string filename, const char *suffix, TGAImage &image);
};

} // namespace

#endif // MODEL_H
